package com.yyds.oneservice.controller;


import com.yyds.common.R;
import com.yyds.oneservice.annotation.UnInterception;
import com.yyds.oneservice.pojo.Product;
import com.yyds.oneservice.service.impl.ProductServiceImpl;
import com.yyds.oneservice.vo.UserProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author lxy
 * @since 2022-12-12
 */
@Api(tags = "商品使用的接口")
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductServiceImpl productService;

    @GetMapping("/firstshow")
    @ApiOperation(value = "首页展示的信息-产品-用户")
    @UnInterception
    public R firstshow(){

        List<UserProductVo> userProductVo = productService.findUserProductVo();
        return R.ok().data("data",userProductVo);
    }
    @GetMapping("/findByProductId")
    @ApiOperation(value = "查看商品的信息")
    @UnInterception
    public R findByProductId(String productId){
        Product byId = productService.getById(productId);
        if(byId==null){
            return R.error().message("商品信息已经被删除啦！请换一家看看");
        }else{
            return R.ok().data("data",byId);
        }
    }
}
